package com.bgs.controller;


import com.bgs.pojo.Detailed;
import com.bgs.pojo.Social;
import com.bgs.pojo.SocialDetails;
import com.bgs.service.SocialDetailsService;
import com.bgs.service.SocialService;
import com.bgs.tool.R;
import com.bgs.vo.SocialDetailsVo;
import com.bgs.vo.SocialDetailsVos;
import com.bgs.vo.SocialVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 社保表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-05-16
 */
@RestController
@CrossOrigin
@RequestMapping("/social-details")
@Slf4j
public class SocialDetailsController {

    @Autowired
    private SocialService socialService;
    @Autowired
    private SocialDetailsService socialDetailsService;


    @ApiOperation(value = "所有社保详情表列表")
    @PostMapping("/findAll")
    public R findAllSocial(@RequestBody(required = false) SocialDetailsVos sVO){
        log.info("模糊查询前端传过来的数据SocialDetailsVos"+sVO);
        PageHelper.startPage(sVO.getPage(),sVO.getLimit());

        List<SocialDetailsVo> slist = socialDetailsService.findAllSocialDetails(sVO);
        PageInfo<SocialDetailsVo> pageInfo = new PageInfo<SocialDetailsVo>(slist);

        return  R.ok().data("total",pageInfo.getTotal()).data("rows",pageInfo.getList());
    }


    @ApiOperation(value = "根据ID值查询社保")
    @GetMapping("/getIdSocial/{sid}")
    public R getIdSocial(
            @ApiParam(name = "sid", value = "社保ID", required = true)
            @PathVariable Integer sid){
        Social m = socialService.selectByPrimaryKey(sid);
        return R.ok().data("social",m);
    }

    @ApiOperation(value = "修改（需要有ID值）")
    @PostMapping("/updateSocialDet")
    public R updateMoney(@RequestBody SocialDetails s){

        boolean flag = socialDetailsService.updateByPrimaryKeySelective(s);
        if (flag){
            return R.ok();
        }else {
            return R.error();
        }
    }



}

